import axios from 'axios'
import {getCookie} from './cookie'

const request = axios.create({

  baseURL:process.env.VUE_APP_API,
  timeout:10000
});

request.interceptors.request.use(config => {
  //设置请求头
  config.headers.token = getCookie('token');
  // config.headers.token = '123456'
  return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
})
request.interceptors.response.use(response => {
  return response;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
})

//get请求
export function get(url,param){
  //删除空数据
  for (var key in param){
    if (param[key] == null) {
      delete param[key];
    }
  }
  return request({
    url:url,
    method:'get',
    params:param
  })
}

//post请求
export function post(url,param){
  //删除空数据
  for (var key in param){
    if (param[key] == null) {
      delete param[key];
    }
  }
  return request({
    url:url,
    method:'post',
    data:param
  })
}

//delete请求
export function deleteRequest(url,param){
  //删除空数据
  for (var key in param){
    if (param[key] == null) {
      delete param[key];
    }
  }
  return request({
    url:url,
    method:'delete',
    params:param
  })
}